﻿using System.Diagnostics;

namespace DimensionsHelper.LanguageService.Syntax;

public class GlobalSqlVariablesSection : DmsSectionWithDescription
{
    private DmsProperty? _connectionString;
    private DmsProperty? _selectQuery;

    internal GlobalSqlVariablesSection(SyntaxToken declareKeywordToken, Identifier name,
        StringLiteral? description, SyntaxNode? parent) :
        base(SyntaxKinds.GlobalSqlVariablesSection, declareKeywordToken, name, description, parent)
    {
    }


    /// <summary>
    ///     ConnectionString = "connection_string"
    /// </summary>
    public DmsProperty? ConnectionStringProperty => _connectionString;


    /// <summary>
    ///     SelectQuery = "select_query"
    /// </summary>
    public DmsProperty? SelectQueryProperty => _selectQuery;


    public GlobalSqlVariablesSection Update(DmsProperty? connectionString,
        DmsProperty? selectQuery)
    {
        SetChildNullableField(ref _connectionString, null, connectionString);
        SetChildNullableField(ref _selectQuery, null, selectQuery);
        return this;
    }


    public override void AcceptVisitor<T>(SyntaxNodeVisitor<T> visitor)
    {
        Accept(visitor, DeclareKeywordToken, NameIdentifier, Description,
            ConnectionStringProperty, SelectQueryProperty);
    }
}


public static partial class NodeFactory
{
    public static GlobalSqlVariablesSection CreateGlobalSqlVariablesSection(SyntaxNode? parent,
        SyntaxToken declareKeywordToken, Identifier identifierName, StringLiteral? description,
        DmsProperty? connectionString, DmsProperty? selectQuery)
    {
        Debug.Assert(declareKeywordToken.IsNode(SyntaxKinds.GlobalSqlVariablesKeywordToken));
        GlobalSqlVariablesSection section = new(declareKeywordToken, identifierName,
            description, parent);
        return section.Update(connectionString, selectQuery);
    }
}